﻿using System;
using System.IO;
using System.IO.Compression;
using System.Text;
using System.Web;
using System.Web.Hosting;
using System.Web.Http;

namespace WebPackaging.Controllers
{
    public class PackageController : ApiController
    {
       // GET api/<controller>/5
        public string Get(string packageName)
        {
            string path = HostingEnvironment.MapPath("/Client/" + packageName);
            string pathzip = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".zip");
            ZipFile.CreateFromDirectory(path, pathzip, CompressionLevel.NoCompression, false, Encoding.UTF8);
            var bytes = File.ReadAllBytes(pathzip);
            File.Delete(pathzip);
            return Convert.ToBase64String(bytes);
        }
    }
}